var prefix = ctx + "manage/antiCheat";
var prefixAntiCheatDetail = ctx + "manage/antiCheatDetail";

$(function () {
    var options = {
        url: prefix + "/list",
        queryParams: queryParams,
        columns: [
            {
                checkbox: true
            },
            {
                field: 'usId',
                title: '用户ID'
            },
            {
                field: 'usNickname',
                title: '用户名'
            },
            {
                field: 'riskScore',
                title: '风险分'
            },
            {
                field: 'riskLevel',
                title: '风险等级',
                formatter: function (value, row, index) {
                    if (value === "PASS") {
                        return '<span class="badge badge-primary">PASS</span>';
                    }
                    if (value === "VERIFY") {
                        return '<span class="badge badge-info">VERIFY</span>';
                    }
                    if (value === "RISK") {
                        return '<span class="badge badge-danger">RISK</span>';
                    }
                }
            },
            {
                field: 'simulator',
                title: '模拟器',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'debug',
                title: '调试',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'wifiProxy',
                title: 'wifi代理',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'javaHook',
                title: 'javaHook',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'vpnProxy',
                title: 'vpn代理',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'doubleOpen',
                title: '双开',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'zid',
                title: '可信id'
            },
            {
                field: 'root',
                title: '是否root',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'nativeHook',
                title: '本地hook',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'ahook',
                title: 'aHook',
                formatter: function (value, row, index) {
                    if (value === 0) {
                        return '<span class="badge badge-primary">否</span>';
                    }
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                }
            },
            {
                field: 'updateTime',
                title: '更新时间'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                    actions.push('<a class="btn btn-primary btn-sm ' + antiCheatDetailAdd + '" href="#" title="编辑" mce_href="#" onclick="updateStatus(\'' + row.usId + '\')"><i class="fa fa-edit"></i>封号</a> ');
                    actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
                    return actions.join('');
                }
            }]
    };
    $.ryTable.init(options);
});

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
}

function queryParams(params) {
    var createTime = $('#createTime').val();
    return {
        // 传递参数查询参数
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        arChannel: $("#arChannel option:selected").val(),
        simulator: $("#simulator option:selected").val(),
        debug: $("#debug option:selected").val(),
        wifiProxy: $("#wifiProxy option:selected").val(),
        javaHook: $("#javaHook option:selected").val(),
        vpnProxy: $("#vpnProxy option:selected").val(),
        doubleOpen: $("#doubleOpen option:selected").val(),
        root: $("#root option:selected").val(),
        nativeHook: $("#nativeHook option:selected").val(),
        aHook: $("#aHook option:selected").val(),
        riskLevel: $("#riskLevel option:selected").val(),
        usId: $("#usId").val(),
        startRiskScore: $("#startRiskScore").val(),
        endRiskScore: $("#endRiskScore").val(),
        usNickname: $("#usNickname").val(),
        startTime: createTime === '' ? '' : startCreatTime,
        endTime: createTime === '' ? '' : endTime
    };
}

function updateStatus(id) {
    var url = prefixAntiCheatDetail + "/add/" + id;
    layer_showAuto("新增封号记录", url);
}

/*反作弊-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增反作弊", url);
}

/*反作弊-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改反作弊", url);
}

// 单条删除
function remove(id) {
    $.modalConfirm("确定要删除选中反作弊吗？", function () {
        _ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
    var rows = $.getSelections("id");
    if (rows.length == 0) {
        $.modalMsg("请选择要删除的数据", "warning");
        return;
    }
    $.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
        _ajax(prefix + '/batchRemove', {"ids": rows}, "post");
    });
}
